package com.easy.persondemo;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.easylib.base.BaseActivity;
import com.guyj.CommonAdapter;
import com.guyj.base.ViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;

public class Info3Activity extends BaseActivity {


    @Bind(R.id.ll_rv)
    LinearLayout ll_rv;
    @Bind(R.id.rv_info)
    RecyclerView tvInfo;
    @Bind(R.id.tv_num)
    TextView tv_num;
    LinearLayoutManager llmpdf;
    List<String> datas;

    @Override
    public int getContentViewId() {
        return R.layout.activity_info2;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {

    }

    @Override
    protected void initVariable() {
        llmpdf = new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false);
    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {
        datas = new ArrayList<>();
        datas.add("吴秀波");
//        datas.add("吴秀");
//        datas.add("吴波");
//        datas.add("吴秀秀");
//        datas.add("吴波波");
//        datas.add("吴吴波");
//        datas.add("吴秀吴");
//        datas.add("吴吴吴");
//        datas.add("波波秀");
//        datas.add("秀秀波");
//        datas.add("波秀吴");
//        datas.add("秀秀吴");

        tvInfo.setLayoutManager(llmpdf);
        tvInfo.setAdapter(new CommonAdapter<String>(mContext, R.layout.item_pdf, datas) {
            @Override
            protected void convert(ViewHolder viewHolder, String o, int i) {
                viewHolder.setText(R.id.tv_pdf, 1 + i + "");
                switch (i) {
                    case 0:
                        ((ImageView) viewHolder.getView(R.id.iv_pdf)).setImageResource(R.drawable.yiti1);
                        break;
                    case 1:
                        ((ImageView) viewHolder.getView(R.id.iv_pdf)).setImageResource(R.drawable.yiti02);
                        break;
                }

                viewHolder.setOnClickListener(R.id.iv_pdf, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (ll_rv.getVisibility() == View.VISIBLE) {
                            ll_rv.setVisibility(View.GONE);
                        } else {
                            ll_rv.setVisibility(View.VISIBLE);
                        }
                    }
                });
            }
        });
        tvInfo.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                int i = llmpdf.findLastVisibleItemPosition();
                tv_num.setText(i + 1 + "/1");
            }
        });

    }

    @OnClick({R.id.tv_shouye, R.id.activity_info})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_shouye:
                finish();
                break;
            case R.id.activity_info:
                if (ll_rv.getVisibility() == View.VISIBLE) {
                    ll_rv.setVisibility(View.GONE);
                } else {
                    ll_rv.setVisibility(View.VISIBLE);
                }
                break;
        }
    }
}
